package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.RepairUrgent;
import com.ruibang.glass.equipment.entity.device.ScrapReport;
import com.ruibang.glass.equipment.service.RepairUrgentService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 *紧急抢修
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/repair/urgent")
@Api(value = "紧急抢修")
public class RepairUrgentController {
    @Autowired
    private RepairUrgentService repairUrgentService;

    @PostMapping("list")
    @ApiOperation(value = "检修工作单列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageRea) {
        return ResultBody.success(repairUrgentService.queryPage(deviceAllPageRea));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody RepairUrgent repairUrgent) {
        return ResultBody.success(repairUrgentService.updateOrAddById(repairUrgent));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody RepairUrgent repairUrgent) {
        if (CollectionUtils.isNotEmpty(repairUrgent.getIds())) {
            repairUrgentService.lambdaUpdate().set(RepairUrgent::getIsDelete, Constants.ONE_STR).in(RepairUrgent::getId, repairUrgent.getIds()).update();
        }
        if (StringUtils.isNoneBlank(repairUrgent.getId())) {
            repairUrgentService.lambdaUpdate().set(RepairUrgent::getIsDelete, Constants.ONE_STR).eq(RepairUrgent::getId, repairUrgent.getId()).update();
        }

        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getOne(@RequestBody RepairUrgent repairUrgent) {
        return ResultBody.success(repairUrgentService.getById(repairUrgent.getId()));
    }


}
